public class Question {
    public static void main(String[] args) {
//        int[] nums = {2,3,5,4,1};
        int[] nums = {2,1,3,5,4};
        int length=nums.length;
        int result=0;
        int common=0;
        for(int i=0;i<length;i++){
            if(nums[i]==i+1){
                common++;
            }
        }
        for(int i=0;i<length;i++){
            if(nums[i]!=i+1){
                if(nums[nums[i]-1]==nums[i]){
                    result++;
                }
            }
        }
        System.out.println(length-common-result-1);
    }
}
